/*
 * Copyright (C) 2013 Fabiano Tarlao
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.easybenchmark.client.testengines;

//  Eratosthenes Sieve prime number benchmark in Java

public class Sieve  {

  
  String results1, results2;
  int SIZE = 8190;
  boolean flags[]; 
  int i, prime, k, iter;
  int count;

    public final void setSIZE(int SIZE) {
        this.SIZE = SIZE;
        flags = new boolean[SIZE+1];
    }
  
  
  /**
   * number of prime numbers
   * @param SIZE
   */
  public Sieve(int SIZE) {
        this.setSIZE(SIZE);      
  }


    /**
     * Sieve calculates iteration/sec but I calculate execution time and veraeg execution time.. so I have isolated the Sieve core
     * which calculates the n prime numbers.
     */
    public int runModifiedSieve() {    
        count=0;
        for(i=0; i<=SIZE; i++) flags[i]=true;
        for (i=0; i<=SIZE; i++) {
           if(flags[i]) {
              prime=i+i+3;
              for(k=i+prime; k<=SIZE; k+=prime)
                 flags[k]=false;
              count++;
           }
        }    
        return(count);
  }

}